//
//  AtYiQiVC.m
//  u76ho
//
//  Created by m-air-01 on 15/12/25.
//  Copyright © 2015年 LV. All rights reserved.
//

#import "AtYiQiVC.h"
#import "InServerCompangyVC.h"
#import "MyfightersVC.h"
#import "MyDynamicsVC.h"
#import "AnnouncementsVC.h"
#import "AtYiQiCell.h"
#import "LoginViewController.h"
@interface AtYiQiVC ()
<
UITableViewDataSource,UITableViewDelegate,UIAlertViewDelegate
>
{
    UITableView * _tableView;
    NSMutableArray * dataSource;
    NSMutableArray * picArr;
}
//@property(nonatomic,strong)CCEaseRefresh * Refresh;

@end
@implementation AtYiQiVC
#pragma mark - 视图生命周期
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];

    
    
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:YES];
}
-(void)viewDidLoad
{
//    UIBarButtonItem *backBarButton = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];
//    
//    self.navigationItem.backBarButtonItem = backBarButton;
    
    self.navigationItem.title = @"在益企";
    

    
    
    [super viewDidLoad];
    [self main];
    

}
-(void)main
{
    dataSource = [[NSMutableArray alloc]init];
    picArr = [[NSMutableArray alloc]init];
    [picArr addObjectsFromArray:@[@"在职公司图标",@"我的站友",@"我的动态",@"企业公告"]];
    [dataSource addObjectsFromArray:@[@"在职公司",@"我的战友",@"我的动态",@"企业公告"]];
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0,64, SCREEN_WIDTH, SCREEN_HEIGHT-64-49) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [_tableView registerNib:[UINib nibWithNibName:@"AtYiQiCell" bundle:nil] forCellReuseIdentifier:@"AtYiQiCell"];
//    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableView.separatorColor = [UIColor grayColor];
    _tableView.tableHeaderView = [[UIView alloc]init];
    _tableView.tableFooterView = [[UIView alloc]init];
    _tableView.backgroundColor = UIColorFromRGB(0xf1f3f3);
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self.view addSubview:_tableView];
    
//    _tableView.contentInset = UIEdgeInsetsMake(64, 0, 0, 0);
//    
//    
//    _Refresh = [[CCEaseRefresh alloc] initInScrollView:_tableView];
//    [ _Refresh addTarget:self action:@selector(dropViewDidBeginRefreshing:) forControlEvents:UIControlEventValueChanged];
//    
//    // auto refresh
//    [_Refresh beginRefreshing];
//

    
}

//-(void)dropViewDidBeginRefreshing:(CCEaseRefresh *)refreshControl{
//    
//    double delayInSeconds = 1.0;
//    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
//    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
//        [_Refresh endRefreshing];
//        
//        
//    });
//    
//    
//    
//    
//}
#pragma mark - UITableViewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return dataSource.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    AtYiQiCell * cell = [tableView dequeueReusableCellWithIdentifier:@"AtYiQiCell"];
    cell.contentLab.text = [dataSource objectAtIndex:indexPath.row];
    cell.headerImg.image = [UIImage imageNamed:picArr[indexPath.row]];
    if (indexPath.row == 1 || indexPath.row == 2) {
        cell.isOne = NO;
    }
    else
    {
        cell.isOne = YES;
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([self isLogin]) {
        if (indexPath.row == 0) {
            
            if ([Singleton share].yqcode == nil || [[Singleton share].yqcode isEqualToString:@"0"]) {
                [Singleton alerSendMessage:@"您还没有被加入任何公司，快去寻找自己钟意的企业，益企发现！"];
            }
            else
            {
                InServerCompangyVC * inscVC = [[InServerCompangyVC alloc]init];
                inscVC.hidesBottomBarWhenPushed = YES;
                
                [self.navigationController pushViewController:inscVC animated:YES];
                //inscVC.hidesBottomBarWhenPushed = NO;
            }
        }
        else if (indexPath.row == 1)
        {
            MyfightersVC * myfVC = [[MyfightersVC alloc]init];
            myfVC.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:myfVC animated:YES];
            //myfVC.hidesBottomBarWhenPushed = NO;
        }
        else if (indexPath.row == 2)
        {
            InServerCompangyVC * inscVC = [[InServerCompangyVC alloc]init];
            inscVC.isMydyna = @"mine";
            
            inscVC.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:inscVC animated:YES];
           // inscVC.hidesBottomBarWhenPushed = NO;
            
        }
        else
        {
            AnnouncementsVC * aVC = [[AnnouncementsVC alloc]init];
            aVC.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:aVC animated:YES];
//            aVC.hidesBottomBarWhenPushed = NO;
        }
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 75;
}
-(BOOL)isLogin
{
    
    if ([Singleton share].code) {
        NSLog(@"登录了");
        return YES;
        
    }
    else
    {
//        NSLog(@"还没登录呢");
//        LoginViewController * loginVC = [[LoginViewController alloc]init];
//        [self.navigationController pushViewController:loginVC animated:NO];
//        return NO;
        if (SYSTEM_VERSION >= 8.0) {
            UIAlertController * alerVC = [UIAlertController alertControllerWithTitle:@"提示" message:@"您还没有登录是否登录" preferredStyle:UIAlertControllerStyleAlert];
            [alerVC addAction:[UIAlertAction actionWithTitle:@"登录" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                
                LoginViewController * loginVC = [[LoginViewController alloc]init];
                
                UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
                nav.navigationBarHidden = YES;
                
                //[self.navigationController pushViewController:nav animated:YES];
                [self presentViewController:nav animated:YES completion:nil];
                
//                LoginViewController * loginVC = [[LoginViewController alloc]init];
//                [self presentViewController:loginVC animated:YES completion:nil];
            }]];
            [alerVC addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                
                
                
            }]];
            [self.view.window.rootViewController presentViewController:alerVC animated:YES completion:nil];

        }
        else
        {
            UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"您还没有登录是否登录" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
            [alert show];
        }
        return NO;

    }
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    int i = (int)buttonIndex;
    if (i == 0) {
        
    }
    else if(i == 1)
    {
        LoginViewController * loginVC = [[LoginViewController alloc]init];
        
        UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
        nav.navigationBarHidden = YES;
        
        //[self.navigationController pushViewController:nav animated:YES];
        [self presentViewController:nav animated:YES completion:nil];
        
        
       
    }
}


@end
